<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>五彩水果城</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<link rel="stylesheet" type="text/css" href="${base}/static/css/reg.css">
	<script type="text/javascript" src="${base}/static/js/lib/jquery-1.9.1.min.js"></script> 	
	<script type="text/javascript" src="${base}/static/js/alert.js"></script>	
  </head>
  
  <body>
  	<header>
  		<div class="reg-top">
  			<a href="${base}/" title="首页" alt="首页" onclick="index()"><h1>五彩水果城</h1></a>
  		</div>
  	</header>
  	<section>
  		<div class="reg-content">
  			<div class="content-right">
  				<div class="reg-title">账号注册</div>
  				<div class="reg-form">
  					<form id="regForm" class="regForm">
  						<label><input type="text" placeholder="请输入用户名" id="username" class="user"></label>
  						<label><input type="password" placeholder="请输入密码" id="password" class="user"></label>
  						<label><input type="password" placeholder="请再次输入密码" id="conf_password" class="user"></label>
  						<label><input type="text" placeholder="请输入常用的邮箱作为验证及找回密码使用" id="email" class="user"></label>
  						<div class="code">
  							<input type="text" placeholder="请输入验证码" class="codeinput" id="codeinput" name="code">
  							<img src="${base}/getcode"  onclick="this.src='${base}/getcode?d='+Math.random()"/>
  						</div>
  						<div class="agreement">
  							<input type="checkbox" name="agree" class="agree">&nbsp;&nbsp;阅读并同意
  							<a href="" title="阅读并同意">《服务协议》</a>
  						</div>
  						<div class="submit-button">
  							<input type="submit" value="立即注册" class="submit" id="submit" onclick="reg()">
  						</div>
  						<div class="toLogin">已有账号？立即<a href="${base}/tologin">登录</a></div>
  					</form>
  				</div>
  				<div class="to-login"></div>
  			</div>
  		</div>
  	</section>
  	<footer>
  		<div class="reg-bottom">
  			<div class="bottom-content">
  				<a href="">首页</a>
  				<a href="">合作及洽谈</a>
  				<a href="">联系我们</a>
  				<a href="">关于我们</a>
  			</div>
  			<div class="copyright">
  				<span>Copyright 2017</span>
  			</div>
  			
  		</div>
  	</footer>
  	
  	
 
  <script type="text/javascript">
  
  	function reg(){
  		var username =$("#username").val();
  		var password =$("#password").val();
  		var email =$("#email").val();
  		var conf_password =$("conf_password").val();
  		if(username==""){
  			alert("用户名不能为空");
  			return false;
  		}
  		if(password==""){
  			alert("密码不能为空");
  			return false;
  		}
  		if(password.length< 6){
  				alert("密码不能少于6位数");
  				return false;
  			}
  		if(conf_password != password){
  			alert("两次密码必须一致");
  			return false;
  		}
  		/*function isEmail(email){ 
		var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/; 
		return reg.test(email); 
		
		} 
		if(!isEmail(emil)){
			alert("请输入正确的邮箱");
			return false;
		}*/
  		$.ajax({
  			type:"post",
  			url:"${base}/reg",
  			cache:false,
  			async:false,
  			data:{username:username,password,password,email,email},
  			dataType:"json",
  			success:function(data){
  				if(data.code==200){
  					layer_alert("注册成功");
  				}else{
  					alert("注册失败");
  				}
  			}
  		});
  	}
  

 	
  	
  /* function reg(){
	  $.post("${base}/reg",{username:username,password,password,email,email},function(data){
	  		if(data.code==200){
					alert("注册成功！")
				}else{
					alert("注册失败")
				}
	  });
  }*/
  
  </script>
  </body>
</html>
